﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net;
using System.IO;
using System.Web;

namespace iApprove.EmailSending
{
    public class SendEmail

    {

        public string SendEmailToUser(string ReceiverEmail)
        {

            MailMessage msg = new MailMessage();

            msg.From = new MailAddress("mscommunity.sgs@gmail.com");
            msg.To.Add(ReceiverEmail);          
            StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("TestEmailTemplate.html"));
            string readFile = reader.ReadToEnd();
            string StrContent = "";
            StrContent = readFile;
            
 
            msg.Subject = "Test Mail";
            msg.Body = StrContent.ToString();
            msg.IsBodyHtml = true;

            //msg.Body = "hi to you ... :)";
            SmtpClient client = new SmtpClient("smtp.gmail.com"); 
            client.UseDefaultCredentials = false;
        
            client.Port = 587;
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials = new NetworkCredential("mscommunity.sgs@gmail.com", "mscomm@2208#sgs");
            client.Timeout = 20000;
            try
            {
                client.Send(msg);
                return "Mail has been successfully sent!";
            }
            catch (Exception ex)
            {
                return "Fail Has error" + ex.Message;
            }
            finally
            {
                msg.Dispose();
            }
        }
    }
}